package com.ganmiao.web.portal.controller.sys;

import com.ganmiao.resp.CommonResultRes;
import com.ganmiao.resp.MobBaseRes;
import com.ganmiao.resp.PageResult;
import com.ganmiao.resp.ResponseCode;
import com.ganmiao.server.sys.entity.SysMenu;
import com.ganmiao.server.sys.query.SysMenuQuery;
import com.ganmiao.server.sys.service.SysMenuService;
import com.ganmiao.server.sys.validated.Add;
import com.ganmiao.server.sys.validated.Update;
import com.ganmiao.server.sys.vo.SysMenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单信息
 */
@Api(tags = "菜单信息")
@Slf4j
@RestController
@RequestMapping("/sysMenu")
public class SysMenuController {

    //菜单信息
    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 新增菜单信息
     *
     * @param sysMenu
     * @return
     */
    @ApiOperation("新增菜单信息")
    @PostMapping("/addSysMenu")
    public MobBaseRes addSysMenu(@RequestBody @Validated(Add.class) SysMenu sysMenu) {
        return sysMenuService.addSysMenu(sysMenu) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "新增菜单信息成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "新增菜单信息失败");
    }

    /**
     * 删除菜单信息
     *
     * @param menuId
     * @return
     */
    @ApiOperation("删除菜单信息")
    @PutMapping("/deleteSysMenu/{menuId}")
    public MobBaseRes deleteSysMenu(@Validated @PathVariable Integer menuId) {
        return sysMenuService.deleteSysMenu(menuId) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "删除菜单信息成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "删除菜单信息失败");
    }

    /**
     * 修改菜单信息
     *
     * @param sysMenu
     * @return
     */
    @ApiOperation("修改菜单信息")
    @PutMapping("/updateSysMenu")
    public MobBaseRes updateSysMenu(@RequestBody @Validated(Update.class) SysMenu sysMenu) {
        return sysMenuService.updateSysMenu(sysMenu) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "修改菜单信息成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "修改菜单信息失败");
    }

    /**
     * 获取菜单信息 (分页)
     *
     * @param sysMenuQuery
     * @return
     */
    @ApiOperation("获取菜单信息 (分页)")
    @GetMapping("/getSysMenuList")
    public CommonResultRes<List<SysMenuVo>> getSysMenuList(SysMenuQuery sysMenuQuery) {
        return new CommonResultRes<>(sysMenuService.getSysMenuList(sysMenuQuery));
    }

    /**
     * 获取菜单信息 (详情)
     *
     * @param menuId
     * @return
     */
    @ApiOperation("获取菜单信息 (详情)")
    @GetMapping("/getSysMenu/{menuId}")
    public CommonResultRes<SysMenuVo> getSysMenu(@Validated @PathVariable Integer menuId) {
        return new CommonResultRes<>(sysMenuService.getSysMenu(menuId));
    }

}
